Skip to content

[common][flink] Fix missing cast rule for DATE/TIME/TIMESTAMP to bounded CHAR/VARCHAR - #9670

Merged
JingsongLi merged 1 commit into
apache:masterfrom
jackylee-ch:casting-string-family
Sep 11, 2026
Merged

JingsongLi merged 1 commit into
apache:masterfrom
jackylee-ch:casting-string-family

Conversation

@jackylee-ch

Copy link
Copy Markdown
Contributor

Purpose

The three date/time-to-string cast rules target VarCharType.STRING_TYPE, so CastExecutors only matches a type equal to it — a bounded VARCHAR(n)/CHAR(n), or a plain STRING NOT NULL, resolves to no rule. SchemaManagerUtils treats a null executor as a rejection even though DataTypeCasts.supportsCast allows the change, so ALTER TABLE T MODIFY (b VARCHAR(10)) on a TIMESTAMP(3) column fails with "cannot be converted to VARCHAR(10) without losing information", while the same statement on an INT column works.

Keyed on DataTypeFamily.CHARACTER_STRING now, which the class javadoc of all three already claims, trimming and padding through BinaryStringUtils like the numeric and boolean rules. Truncating to a bounded target and blank padding CHAR is existing asserted behaviour for the other scalars (testModifyColumnTypeFromNumericToString, 47d4dd6). This also unblocks Spark's CAST(<datetime> AS VARCHAR(n)) pushdown through CastTransform, with the truncating semantics INT already has.

Tests

DateTimeToCharacterStringCastRuleTest, and SchemaChangeITCase.testModifyColumnTypeFromTimestampToBoundedString, which fails on master with the exception above.

Written with Claude Code; reasoning and verification are mine.

…ded CHAR/VARCHAR

DateToStringCastRule, TimeToStringCastRule and TimestampToStringCastRule
registered VarCharType.STRING_TYPE as their target, so CastExecutors only
matched a type equal to it. A bounded VARCHAR/CHAR target, or a plain
STRING NOT NULL, resolved to no rule, and SchemaManagerUtils rejects the
column type change when the executor is null even though
DataTypeCasts.supportsCast allows it.

Key them on DataTypeFamily.CHARACTER_STRING, which the class javadoc here
already claims, and trim or pad through BinaryStringUtils like the numeric
and boolean rules. Bounded character targets already truncate and blank
pad for the other scalar types, asserted since 47d4dd6.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema-change path currently allows datetime-to-character conversion but cannot resolve an executor for bounded CHAR/VARCHAR targets. The new family-based rules close that mismatch, and their truncation/CHAR padding follows the existing numeric and boolean conversion contract. I also checked null handling in schema reads and the unchanged timestamp/time-zone formatting.

No blocking defect found. All 4 DateTimeToCharacterStringCastRuleTest cases pass with the head rules on JDK 8; I inspected but did not rerun the Flink ALTER TABLE integration case. Tables using the newly supported ALTER need readers with these rules, as older readers cannot perform that conversion.

@JingsongLi
JingsongLi merged commit f87110c into apache:master Sep 11, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants